package com.beep.erp.common.base;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.beep.erp.R;
import com.beep.erp.common.base.viewpage.ViewPageFragmentAdapter;

import butterknife.BindView;

/**
 * FileName: BaseViewPagerFragment
 * description:
 * Author: Jolly
 * Date: 2018/8/23
 */
public abstract class BaseViewPagerFragment<T extends BasePresenter, E> extends BaseFragment<T,E> {

    @BindView(R.id.tab_layout)
    protected TabLayout tabLayout;
    @BindView(R.id.view_pager)
    protected ViewPager viewPager;

    @Override
    protected int getLayoutId() {
        return R.layout.base_viewpage_fragment;
    }

    @Override
    protected void initView(View view) {
        ViewPageFragmentAdapter viewPageFragmentAdapter=new ViewPageFragmentAdapter(getChildFragmentManager(),tabLayout,viewPager);
        onSetupTabAdapter(viewPageFragmentAdapter);
        viewPager.setAdapter(viewPageFragmentAdapter);
        tabLayout.setupWithViewPager(viewPager);//将TabLayout和ViewPager关联起来。
    }

    protected abstract void onSetupTabAdapter(ViewPageFragmentAdapter adapter);
    public void setTablayoutScroll(){
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }
}
